# -*- coding: utf-8 -*-
#


class SIPNetworkMessageType:
    
    Request = "request"
    Response = "response"
    
    
class SIPNetworkMessage:
    
    def __init__(self):
        
        self._uri = None
        self._type = None
        self._service = None
        self._body = None
        
    def setURI(self, uri):
        self._uri = uri
        
    def setType(self, type):
        self._type = type
        
    def setService(self, service):
        self._service = service
        
    def setBody(self, body):
        self._body = body
        
    def getURI(self):
        return self._uri
    
    def getType(self):
        return self._type
    
    def getService(self):
        return self._service
    
    def getBody(self):
        return self._body
    
import threading  
from lib.pjsip import _pjsua 
import weakref 

class SIPTransport(threading.Thread):

    evnt = threading.Event()
    lck = threading.Lock()
        
    def __init__(self, request, reply):
        """
        reply: SIPNetworkMessage
        """
        self._request = request
        self._reply = reply
    
    def run(self):
        msg_data = _pjsua.Msg_Data()
        
        if self._request.getBody():
            msg_data.msg_body = self._request.getBody()
        else:
            msg_data = None
        
        
        SIPTransport.lck.acquire()
        
        _pjsua.call_send_request(self._request.getURI(), "MESSAGE", msg_data)
        
        SIPTransport.lck.release()
        
class SIPTransportCallback:
    
    
    def __init__(self, transport=None):
        self._set_transport(transport)
    
    def _set_transport(self, transport):
        if transport:
            self.transport = weakref.proxy(transport)
        else:
            self.transport = None
            
    def on_pager(self, mime_type, body):
        """
        Notification that incoming instant message is received on
        this call.

        Keyword arguments:
        mime_type  -- MIME type of the instant message body.
        body       -- the instant message body.

        """
        pass
    
    
        
        
        

        
    
        
        
        